<template>
  <div class="page-header-index-wide">
    <a-row :gutter="24">
      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="歌手总数" :total="this.indexChart.countSinger| NumberFormat" style="text-align: center;">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="team" style="font-size: 40px;color: #DD4A68"/>
          </a-tooltip>
          <div>
            <mini-progress color="#1E90FF" :target="1000" :percentage="this.indexChart.countSinger" :height="15" />
          </div>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="歌曲数目" :total="this.indexChart.countSongs | NumberFormat" style="text-align: center;">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="gift" style="font-size: 40px;color: #00DB00"/>
          </a-tooltip>
          <div>
            <mini-progress color="#49CC49" :target="1000" :percentage="this.indexChart.countSongs" :height="15" />
          </div>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="专辑总数" :total="this.indexChart.countAlbums | NumberFormat" style="text-align: center;">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="video-camera" style="font-size: 40px;color: #8cc8ff"/>
          </a-tooltip>
          <div>
            <mini-progress color="rgb(19, 194, 194)" :target="1000" :percentage="this.indexChart.countAlbums" :height="15" />
          </div>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="歌单数量" :total="this.indexChart.countSonglist | NumberFormat" style="text-align: center;">
          <a-tooltip title="指标说明" slot="action" >
            <a-icon type="file-markdown" style="font-size: 40px;color: #00A0E9"/>
          </a-tooltip>
          <div>
            <mini-progress color="#FFA500" :target="1000" :percentage="this.indexChart.countSonglist" :height="15" />
          </div>
        </chart-card>
      </a-col>
    </a-row>

    <a-card :loading="loading" :bordered="false" :body-style="{padding: '0'}">
      <div class="salesCard">
        <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
          <a-tab-pane loading="true" tab="歌曲分布" key="1">
            <a-row>
              <a-col :span="10">
                <a-radio-group style="margin-top: -15px;margin-left: 20px" :value="songCountType" @change="statisticst">
                  <a-radio-button :value="1">按语种统计</a-radio-button>
                  <a-radio-button :value="2">按流派统计</a-radio-button>
                </a-radio-group>
              </a-col>
              <a-col :xl="16" :lg="12" :md="12" :sm="24" :xs="24">
                <bar class="statistic" title="单曲统计" :dataSource="countSongsSource" style="margin-top: 20px"/>
              </a-col>
              <a-col :xl="8" :lg="12" :md="12" :sm="24" :xs="24">
                <a-card title="快速开始 / 便捷导航" style="margin-bottom: 24px" :bordered="false" :body-style="{padding: 0}">
                  <div class="item-group">
                    <a-row>
                      <a-col :class="'more-btn'" :span="10" v-for="(item,index) in registerTypeList" :key=" 'registerType'+index ">
                        <a-button @click="goPage(item.path)" style="margin-bottom:10px" size="small" type="primary" ghost>{{ item.text }}</a-button>
                      </a-col>
                    </a-row>
                  </div>
                </a-card>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane tab="歌手情况" key="2">
            <a-row>
              <a-col :span="10">
                <a-radio-group style="margin-top: -10px;margin-left: 40px" :value="singersCountType" @change="statisticstSingers">
                  <a-radio :value="1">按国家统计</a-radio>
                  <a-radio :value="2">按性别统计</a-radio>
                  <a-radio :value="3">入驻情况</a-radio>
                </a-radio-group>
              </a-col>
              <a-col :xl="16" :lg="12" :md="12" :sm="24" :xs="24">
                <bar v-if="singersCountType==1" class="statistic" title="国家分布统计" :dataSource="countSingersSource" style="margin-top: 20px;"/>
                <pie v-else class="statistic" title="歌手分布" :dataSource="countSingersSource" style="margin-left: -200px"/>
              </a-col>
              <a-col :xl="8" :lg="12" :md="12" :sm="24" :xs="24">
                <a-card title="快速开始 / 便捷导航" style="margin-bottom: 24px" :bordered="false" :body-style="{padding: 0}">
                  <div class="item-group">
                    <a-row>
                      <a-col :class="'more-btn'" :span="10" v-for="(item,index) in registerTypeList" :key=" 'registerType'+index ">
                        <a-button @click="goPage(item.path)" style="margin-bottom:10px" size="small" type="primary" ghost>{{ item.text }}</a-button>
                      </a-col>
                    </a-row>
                  </div>
                </a-card>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane tab="歌单统计" key="3">
            <a-row>
              <a-col :span="10">
                <a-radio-group style="margin-top: -30px;margin-left: 30px" :value="songlistCountType" @change="statisticstSonglist">
                  <a-radio-button :value="1">推荐级别统计</a-radio-button>
                  <a-radio-button :value="2">按地区统计</a-radio-button>
                </a-radio-group>
              </a-col>
              <a-col :xl="16" :lg="12" :md="12" :sm="24" :xs="24">
                <bar class="statistic" title="歌单统计" :dataSource="countSonglistSource" style="margin-top: 20px"/>
              </a-col>
              <a-col :xl="8" :lg="12" :md="12" :sm="24" :xs="24">
                <a-card title="快速开始 / 便捷导航" style="margin-bottom: 24px" :bordered="false" :body-style="{padding: 0}">
                  <div class="item-group">
                    <a-row>
                      <a-col :class="'more-btn'" :span="10" v-for="(item,index) in registerTypeList" :key=" 'registerType'+index ">
                        <a-button @click="goPage(item.path)" style="margin-bottom:10px" size="small" type="primary" ghost>{{ item.text }}</a-button>
                      </a-col>
                    </a-row>
                  </div>
                </a-card>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane tab="专辑统计" key="4">
            <a-row>
              <a-col :span="10">
                <a-radio-group style="margin-top: -30px;margin-left: 30px" :value="albumsCountType" @change="statisticstAlbums">
                  <a-radio-button :value="1">推荐级别统计</a-radio-button>
                  <a-radio-button :value="2">按地区统计</a-radio-button>
                </a-radio-group>
              </a-col>
              <a-col :xl="16" :lg="12" :md="12" :sm="24" :xs="24">
                <bar class="statistic" title="专辑统计" :dataSource="countAlbumsSource" style="margin-top: 20px"/>
              </a-col>
              <a-col :xl="8" :lg="12" :md="12" :sm="24" :xs="24">
                <a-card title="快速开始 / 便捷导航" style="margin-bottom: 24px" :bordered="false" :body-style="{padding: 0}">
                  <div class="item-group">
                    <a-row>
                      <a-col :class="'more-btn'" :span="10" v-for="(item,index) in registerTypeList" :key=" 'registerType'+index ">
                        <a-button @click="goPage(item.path)" style="margin-bottom:10px" size="small" type="primary" ghost>{{ item.text }}</a-button>
                      </a-col>
                    </a-row>
                  </div>
                </a-card>
              </a-col>
            </a-row>
          </a-tab-pane>
        </a-tabs>
      </div>
    </a-card>

    <a-row>
      <a-col :span="24">
        <a-card :loading="loading" :bordered="false" title="最近一周访问量统计" :style="{ marginTop: '24px' }">
          <a-row>
            <a-col :span="6">
              <head-info title="今日IP" :content="loginfo.todayIp"></head-info>
            </a-col>
            <a-col :span="2">
              <a-spin class='circle-cust'>
                <a-icon slot="indicator" type="environment" style="font-size: 24px"  />
              </a-spin>
            </a-col>
            <a-col :span="6">
              <head-info title="今日访问" :content="loginfo.todayVisitCount"></head-info>
            </a-col>
            <a-col :span="2">
              <a-spin class='circle-cust'>
                <a-icon slot="indicator" type="team" style="font-size: 24px"  />
              </a-spin>
            </a-col>
            <a-col :span="6">
              <head-info title="总访问量" :content="loginfo.totalVisitCount"></head-info>
            </a-col>
            <a-col :span="2">
              <a-spin class='circle-cust'>
                <a-icon slot="indicator" type="rise" style="font-size: 24px"  />
              </a-spin>
            </a-col>
          </a-row>
          <line-chart-multid :fields="visitFields" :dataSource="visitInfo"></line-chart-multid>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script>
  import ChartCard from '@/components/ChartCard'
  import ACol from "ant-design-vue/es/grid/Col"
  import ATooltip from "ant-design-vue/es/tooltip/Tooltip"
  import MiniArea from '@/components/chart/MiniArea'
  import MiniBar from '@/components/chart/MiniBar'
  import MiniProgress from '@/components/chart/MiniProgress'
  import RankList from '@/components/chart/RankList'
  import Bar from '@/components/chart/Bar'
  import LineChartMultid from '@/components/chart/LineChartMultid'
  import HeadInfo from '@/components/tools/HeadInfo.vue'

  import Pie from '@/components/chart/Pie'
  import Trend from '@/components/Trend'
  import { getLoginfo,getVisitInfo } from '@/api/api'
  import { deleteAction, getAction,downFile,getFileAccessHttpUrl } from '@/api/manage'

  const rankList = []
  for (let i = 0; i < 7; i++) {
    rankList.push({
      name: '白鹭岛 ' + (i+1) + ' 号店',
      total: 1234.56 - i * 100
    })
  }
  const barData = []
  for (let i = 0; i < 12; i += 1) {
    barData.push({
      x: `${i + 1}月`,
      y: Math.floor(Math.random() * 1000) + 200
    })
  }
  export default {
    name: "IndexChart",
    components: {
      ATooltip,
      Pie,
      ACol,
      ChartCard,
      MiniArea,
      MiniBar,
      MiniProgress,
      RankList,
      Bar,
      Trend,
      LineChartMultid,
      HeadInfo
    },
    data() {
      return {
        loading: true,
        registerTypeList:[
          {
          text:"歌曲查询",
          path: '/cloud/data/music/center/library'
           },
          {
          text:"用户管理",
          path: '/cloud/music/users'
           },
          {
          text:"歌单专辑",
          path: '/cloud/music/albums'
           },
          {
            text:"发布单曲",
            path: '/cloud/music/newalbums'
          },
          {
          text:"歌手查询",
          path: '/cloud/music/singer'
        }],
        center: null,
        rankList,
        barData,
        loginfo:{},
        countSongsSource: [],
        songCountType: 1,
        countSingersSource: [],
        singersCountType: 1,
        songlistCountType: 1,
        countSonglistSource: [],
        albumsCountType: 1,
        countAlbumsSource: [],
        indexChart:{},
        visitFields:['ip','visit'],
        visitInfo:[],
        indicator: <a-icon type="loading" style="font-size: 24px" spin />
      }
    },
    created() {
      setTimeout(() => {
        this.loading = !this.loading
      }, 1000)
      this.loadSongCount();
      this.loadSingersCount();
      this.loadSonglistCount();
      this.loadAlbumsCount();
      this.initLogInfo();
      this.getIndexChart();
    },
    methods: {
      goPage(path){
        this.$router.push({ path:path});
      },
      loadSongCount(){
        this.countSongsSource = [];
        getAction(`/mus/index/song/chart?type=${this.songCountType}`).then((res) => {
          if (res.success) {
            this.getSongsLanguageCountSource(res.result);
          }else {
            this.countSongsSource = [];
          }
        })
      },
      loadSingersCount() {
        this.countSingersSource = [];
        getAction(`/mus/index/singers/chart?type=${this.singersCountType}`).then((res) => {
          if (res.success) {
            this.getSingersCountSource(res.result);
          }else {
            this.countSingersSource = [];
          }
        })
      },
      loadSonglistCount() {
        this.countSonglistSource = [];
        getAction(`/mus/index/songlist/chart?type=${this.songlistCountType}`).then((res) => {
          if (res.success) {
            this.getSonglistCountSource(res.result);
          }else {
            this.countSonglistSource = [];
          }
        })
      },
      getSonglistCountSource(data) {
        for (let i = 0; i < data.length; i++) {
          this.countSonglistSource.push({
            x: `${data[i].categoryname}`,
            y: data[i].categorycount
          })
        }
      },
      loadAlbumsCount() {
        this.countAlbumsSource = [];
        getAction(`/mus/index/albums/chart?type=${this.albumsCountType}`).then((res) => {
          if (res.success) {
            this.getAlbumsCountSource(res.result);
          }else {
            this.countAlbumsSource = [];
          }
        })
      },
      getAlbumsCountSource(data) {
        for (let i = 0; i < data.length; i++) {
          this.countAlbumsSource.push({
            x: `${data[i].categoryname}`,
            y: data[i].categorycount
          })
        }
      },
      getSongsLanguageCountSource(data){
        for (let i = 0; i < data.length; i++) {
          this.countSongsSource.push({
            x: `${data[i].categoryname}`,
            y: data[i].categorycount
          })
        }
      },
      getSingersCountSource(data){
        if (this.singersCountType==1){
          for (let i = 0; i < data.length; i++) {
            this.countSingersSource.push({
              x: `${data[i].categoryname}`,
              y: data[i].categorycount
            })
          }
        }else {
          for (let i = 0; i < data.length; i++) {
            this.countSingersSource.push({
              item: data[i].categoryname,
              count:data[i].categorycount
            })
          }
        }
      },
      // 选择统计类别
      statisticst(e) {
        this.songCountType = e.target.value;
        this.loadSongCount();
      },
      statisticstSingers(e){
        this.singersCountType = e.target.value;
        this.loadSingersCount();
      },
      statisticstSonglist(e){
        this.songlistCountType = e.target.value;
        this.loadSonglistCount();
      },
      statisticstAlbums(e){
        this.albumsCountType = e.target.value;
        this.loadAlbumsCount();
      },
      getIndexChart(){
        getAction(`/mus/sys/api/index/chart`).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.indexChart = res.result.chart;
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{

          }
        }).finally(() => {

        })
      },
      initLogInfo () {
        getLoginfo(null).then((res)=>{
          if(res.success){
            Object.keys(res.result).forEach(key=>{
              res.result[key] =res.result[key]+""
            })
            this.loginfo = res.result;
          }
        })
        getVisitInfo().then(res=>{
          if(res.success){
             this.visitInfo = res.result;
           }
         })
      },

    }
  }
</script>

<style lang="less" scoped>
  .circle-cust{
    position: relative;
    top: 28px;
    left: -100%;
  }
  .extra-wrapper {
    line-height: 55px;
    padding-right: 24px;

    .extra-item {
      display: inline-block;
      margin-right: 24px;

      a {
        margin-left: 24px;
      }
    }
  }

  /* 首页访问量统计 */
  .head-info {
    position: relative;
    text-align: left;
    padding: 0 32px 0 0;
    min-width: 125px;

    &.center {
      text-align: center;
      padding: 0 32px;
    }

    span {
      color: rgba(0, 0, 0, .45);
      display: inline-block;
      font-size: .95rem;
      line-height: 42px;
      margin-bottom: 4px;
    }
    p {
      line-height: 42px;
      margin: 0;
      a {
        font-weight: 600;
        font-size: 1rem;
      }
    }
  }
  .extra-wrapper {
    line-height: 55px;
    padding-right: 24px;

    .extra-item {
      display: inline-block;
      margin-right: 24px;

      a {
        margin-left: 24px;
      }
    }
  }

  .item-group {
    padding: 20px 0 8px 24px;
    font-size: 0;
    a {
      color: rgba(0, 0, 0, 0.65);
      display: inline-block;
      font-size: 14px;
      margin-bottom: 13px;
      width: 25%;
    }
  }

  .item-group {
    .more-btn {
      margin-bottom: 13px;
      text-align: center;
    }
  }

  .list-content-item {
    color: rgba(0, 0, 0, .45);
    display: inline-block;
    vertical-align: middle;
    font-size: 14px;
    margin-left: 40px;
  }

  @media only screen and (min-width: 1600px) {
    .list-content-item{
      margin-left:60px;
    }
  }

  @media only screen and (max-width: 1300px) {
    .list-content-item{
      margin-left:20px;
    }
    .width-hidden4{
      display:none
    }
  }
  .list-content-item{
    span{line-height: 20px;}
  }
  .list-content-item{
    p{margin-top: 4px;margin-bottom:0;line-height:22px;}
  }
  .anty-list-cust {
    .ant-list-item-meta{flex: 0.3 !important;}
  }
  .anty-list-cust {
    .ant-list-item-content{flex:1 !important; justify-content:flex-start !important;margin-left: 20px;}
  }
</style>